Skip to content

Accept every choices input on file, related, array and GIS fields - #3756

Merged
UnknownPlatypus merged 1 commit into
typeddjango:masterfrom
UnknownPlatypus:field-choices-input
Oct 25, 2026
Merged

UnknownPlatypus merged 1 commit into
typeddjango:masterfrom
UnknownPlatypus:field-choices-input

Conversation

@UnknownPlatypus

Copy link
Copy Markdown
Contributor

I have made things!

Field.__init__ already use choices: _ChoicesInput but FileField, the related fields, ArrayField and the GIS fields still took the narrower _Choices iterable, so FileField(choices=Kind), ForeignKey(..., choices={...}) or a callable were rejected.

I've migrated the tests/typecheck/db/models/test_fields_choices.yml test to get better coverage too for other typecheckers and linked a ty issue causing incorrect ignores

Related issues

Ported from sbdchd#408

AI Policy

  • I have read and agree to the AI Policy, removed any "Co-Authored-By" lines attributing coding agents, and manually reviewed the final result

`Field.__init__` and the scalar fields already take `choices: _ChoicesInput` (a `Choices` class, a mapping, a callable or an iterable of pairs), like Django does.
`FileField`, the related fields, `ArrayField` and the GIS fields still took the narrower `_Choices` iterable, so `FileField(choices=Kind)`, `ForeignKey(..., choices={...})` or a callable were rejected.

Ported from sbdchd#408

- [ ] I have read and agree to the [AI Policy](https://github.com/typeddjango/django-stubs/blob/master/.github/AI_POLICY.md), removed any "Co-Authored-By" lines attributing coding agents, and manually reviewed the final result
@UnknownPlatypus
UnknownPlatypus merged commit 446fc08 into typeddjango:master Oct 25, 2026
38 checks passed
@UnknownPlatypus
UnknownPlatypus deleted the field-choices-input branch October 25, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants